<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="使用时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="useTime">
              <j-date placeholder="请选择使用时间"  v-model="model.useTime" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="人员姓名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="useName">
              <j-dict-select-tag type="list" v-model="model.useName" dictCode="" placeholder="请选择人员姓名" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="人员工号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="userJobNumber">
              <j-dict-select-tag type="list" v-model="model.userJobNumber" dictCode="" placeholder="请选择人员工号" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="使用工种" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="useType">
              <j-dict-select-tag type="list" v-model="model.useType" dictCode="" placeholder="请选择使用工种" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工具箱名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="toolboxName">
              <a-input v-model="model.toolboxName" placeholder="请输入工具箱名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工具箱编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="toolboxId">
              <a-input v-model="model.toolboxId" placeholder="请输入工具箱编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工具规格" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="toolSpecifications">
              <a-input v-model="model.toolSpecifications" placeholder="请输入工具规格"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工具名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="toolName">
              <a-input v-model="model.toolName" placeholder="请输入工具名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工具物料码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="toolMaterialCode">
              <a-input v-model="model.toolMaterialCode" placeholder="请输入工具物料码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="关箱总次数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="closeBoxNum">
              <a-input v-model="model.closeBoxNum" placeholder="请输入关箱总次数"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="第几次关箱记录" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="theCloseBoxNum">
              <a-input v-model="model.theCloseBoxNum" placeholder="请输入第几次关箱记录"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="标签总数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tagsNum">
              <a-input v-model="model.tagsNum" placeholder="请输入标签总数"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="当前标签总数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="currentTagsNum">
              <a-input v-model="model.currentTagsNum" placeholder="请输入当前标签总数"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="报警类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="waringType">
              <j-dict-select-tag type="list" v-model="model.waringType" dictCode="waring_type" placeholder="请选择报警类型" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="开箱时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="openBoxTime">
              <j-date placeholder="请选择开箱时间" v-model="model.openBoxTime"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="报警时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="closeBoxTime">
              <j-date placeholder="请选择报警时间" v-model="model.closeBoxTime"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="标签内容" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tagsContent">
              <a-input v-model="model.tagsContent" placeholder="请输入标签内容"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'UseInfoForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           useName: [
              { required: true, message: '请输入人员姓名!'},
           ],
           userJobNumber: [
              { required: true, message: '请输入人员工号!'},
           ],
           useType: [
              { required: true, message: '请输入使用工种!'},
           ],
           toolboxName: [
              { required: true, message: '请输入工具箱名称!'},
           ],
           toolboxId: [
              { required: true, message: '请输入工具箱编号!'},
           ],
           toolSpecifications: [
              { required: true, message: '请输入工具规格!'},
           ],
           toolName: [
              { required: true, message: '请输入工具名称!'},
           ],
           toolMaterialCode: [
              { required: true, message: '请输入工具物料码!'},
           ],
           closeBoxNum: [
              { required: true, message: '请输入关箱总次数!'},
           ],
           theCloseBoxNum: [
              { required: true, message: '请输入第几次关箱记录!'},
           ],
           tagsNum: [
              { required: true, message: '请输入标签总数!'},
           ],
           currentTagsNum: [
              { required: true, message: '请输入当前标签总数!'},
           ],
           waringType: [
              { required: true, message: '请输入报警类型!'},
           ],
           openBoxTime: [
              { required: true, message: '请输入开箱时间!'},
           ],
           closeBoxTime: [
              { required: true, message: '请输入报警时间!'},
           ],
           tagsContent: [
              { required: true, message: '请输入标签内容!'},
           ],
        },
        url: {
          add: "/useinfo/useInfo/add",
          edit: "/useinfo/useInfo/edit",
          queryById: "/useinfo/useInfo/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>